package controllers.Administrador;

import java.util.Collection;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import services.ReunionService;
import controllers.AbstractController;
import domain.Reunion;

@Transactional
@Controller
@RequestMapping("/reunion/administrator")
public class ReunionAdministratorController extends AbstractController {

	@Autowired
	private ReunionService reunionService;

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public ModelAndView list(@RequestParam int comunidadId) {
		ModelAndView result;
		Collection<Reunion> reuniones;

		reuniones = reunionService.findByCommunity(comunidadId);

		result = new ModelAndView("reunion/list");
		result.addObject("requestURI", "reunion/administrator/list.do");
		result.addObject("reuniones", reuniones);
		result.addObject("backURI",
				"/comunidad/administrator/edit.do?comunidadId=" + comunidadId);

		return result;
	}

	@RequestMapping(value = "/edit", method = RequestMethod.GET)
	public ModelAndView edit(@RequestParam int reunionId) {
		ModelAndView result;
		Reunion reunion;
		Boolean isNew;

		reunion = reunionService.findOne(reunionId);
		isNew = false;

		result = new ModelAndView("reunion/details");
		result.addObject("requestURI", "reunion/edit.do");
		result.addObject("reunion", reunion);
		result.addObject("reunionId", reunionId);
		result.addObject("isNew", isNew);
		result.addObject("backURI",
				"/reunion/administrator/list.do?comunidadId="
						+ reunion.getComunidadDeVecinos().getId());

		return result;
	}

}
